// 数字转中文方法
export function numberToChinese(value) {
  const chineseNumbers = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九"];
  const units = ["", "十", "百", "千", "万", "十万", "百万", "千万", "亿", "十亿", "百亿", "千亿", "万亿"];
  if (value === 0) {
    return chineseNumbers[0];
  }
  let result = "";
  let num = value;
  let unitIndex = 0;

  while (num > 0) {
    const digit = num % 10;
    if (digit !== 0) {
      result = chineseNumbers[digit] + units[unitIndex] + result;
    } else if (result !== "" && result[0] !== chineseNumbers[0]) {
      result = chineseNumbers[0] + result;
    }
    num = Math.floor(num / 10);
    unitIndex++;
  }
  return result;
}

// 递归函数，确定节点层级
export function setNodeLevel(node, level) {
  node.levelText = `第${numberToChinese(level)}级`; // 设置节点层级
  node.level = level; // 设置节点层级
  if (node.children && node.children.length > 0) {
    node.children.forEach((child) => {
      setNodeLevel(child, level + 1); // 递归调用，层级加1
    });
  }
}
